﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Omron.Framework
{
    public delegate void IconPressedEventHandler(ActorIcon icon);

    public class ActorIcon : Control
    {
        public ActorIcon(int xLoc, int yLoc, int w, int h, Actor actor)
        {
            Actor = actor;
            width = w;
            height = h;
            x = xLoc;
            y = yLoc;
            bound = new RectPoly(new Vector2(xLoc, yLoc), w, h);
            int barHeight = h / 5;
            hpBar = new Bar(new Vector2(xLoc, yLoc) + new Vector2(0, h - barHeight), w, barHeight);
            hpBar.BackColor = Color.Red;
            hpBar.ForeColor = Color.Green;
            base.MouseLeftUp += new MouseClickEventHandler(ActorIcon_MouseLeftUp);
        }

        void ActorIcon_MouseLeftUp(Vector2 mPos)
        {
            if (IconMouseUp != null)
                IconMouseUp(this);
        }

        public Actor Actor;
        int width, height;
        int x, y;
        RectPoly bound;
        Bar hpBar;

        public event IconPressedEventHandler IconMouseUp;


        public override IPolygon GetBoundingPoly()
        {
            return bound;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(ResourceManager.Resources["pixel"], new Rectangle(x, y, width, height), Color.Brown);
            spriteBatch.Draw(Actor.GetActiveAnimation().GetCurrentFrame().Image, new Rectangle(x, y, width, height), Color.White);
            hpBar.Value = Actor.HealthRatio;
            hpBar.Draw(spriteBatch);
        }
    }
}
